package com.test.rabbitmq.nack;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.util.HashMap;
import java.util.Map;

public class Provider {

    public static void main(String[] args)throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setVirtualHost("testhost");
        factory.setPort(Config.MQ_PORT);
        factory.setHost(Config.MQ_IP);
        factory.setUsername(Config.USER_NAME);
        factory.setPassword(Config.USER_PWD);

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        String msg = "this is a message provide by ack producer";
        for (int i = 0; i < 5; i++){
            Map<String, Object> map = new HashMap<>();
            map.put("pc", "个人笔记本电脑");
            map.put("num", i);
            AMQP.BasicProperties properties = new AMQP.BasicProperties().builder()
                    .deliveryMode(2)
                    .contentEncoding("UTF-8")
                    .headers(map).build();
            channel.basicPublish(Config.EXCHANGE_NAME, Config.ROUTE_KEY, true, properties, msg.getBytes());
            System.out.println("生产者发送第：" + i + " 条消息");
        }
    }
}
